<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
<head>
<base href="<%=basePath%>"></base>
<title>Insert title here</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$(".click").click(function() {
			$(".tip").fadeIn(200);
		});

		$(".tiptop a").click(function() {
			$(".tip").fadeOut(200);
		});

		$(".sure").click(function() {
			$(".tip").fadeOut(100);
		});

		$(".cancel").click(function() {
			$(".tip").fadeOut(100);
		});

	});
	
	//检查用户是否已经存在
	function checkUser(){
		
		var cname_Val = $("#cname").val();//获取id="cname"的文本框的值
		alert(cname_Val);
		//传递参数给cname,给Controlle中的checkUser()
		//返回json格式
		//如果checkUser执行成功
		$.ajax({
			url:"<%=basePath%>checkUser",
			data:{
				"username":cname_Val
			},
			dataType:"json",
			contentType:"application/json;charset=utf-8",//编码格式
			success:function(data){
				if(data.msg != null){
					alert(data.msg);
					$("#msgSpan").
				    $("#cname").val("");
					$("#cname").focus();
				}
			},
			//如果失败
			error:function(){
				alert("后台服务器出错，请联系管理员！")
			}
		})
	}
</script>

</head>


<body>
	<div class="place">
		<span>位置：</span>
		<ul class="placeul">
			<li><a href="getUserInfoList">用户管理</a></li>
			<li><a href="userInfoAdd.jsp">添加</a></li>
		</ul>
	</div>
     
	<form action="userInfoAdd" method="post" >
		<div class="formbody">
			<div class="formtitle">
				<span>用户基本信息</span>
			</div>

            <c:if test="${flag!='1'}">
			<ul class="forminfo">
				<li><label>姓名</label><input name="cname" type="text" class="dfinput" id="cname"
				  value="${member.cname}" onchange="checkUser()"/><font color="red"><span id="msgSpan"></span></font></li>  <!--校验姓名是否已经存在 -->
				<li><label>性别</label><cite><input name="memSex"
						type="radio" checked="checked" value="M" />男&nbsp;&nbsp;&nbsp;&nbsp;<input
						name="memSex" type="radio" value="F" />女</cite></li>
				<li><label>出生日期</label><input name="memBorn" type="text"
					class="dfinput" /></li>
				<li><label>角色</label><cite><select name="roleid" class="dfselect"><option
								value="0">请选择</option>
							<option value="1">管理员</option>
							<option value="2">客户经理</option></select></cite></li>
				<li><label>&nbsp;</label><input name="" type="submit"
					class="btn" value="添加" />&nbsp;&nbsp;&nbsp;&nbsp;<input name=""
					type="reset" class="btn" value="重置" /></li>
			</ul>
         </c:if>
         <!-- 添加成功后显示添加后的值 -->
         <c:if test="${flag=='1'}">
			<ul class="forminfo">
				<li><label>姓名</label><input name="cname" type="text" class="dfinput"
					value="${member.cname}" readonly/></li>
				<li><label>性别</label><cite><input name="memSex" readonly
						type="radio" checked="checked" value="M" 
						<c:if test="${member.memSex=='M'}">
						checked
						</c:if>/>男&nbsp;&nbsp;&nbsp;&nbsp;<input
						name="memSex" type="radio" value="F" 
						<c:if test="${member.memSex=='F'}">
						checked
						</c:if>
						/>女</cite></li>
				<li><label>出生日期</label><input name="memBorn" type="text"
					class="dfinput" value="${member.memBorn}" readonly/></li>
				<li><label>角色</label><cite><select name="roleid" class="dfselect" ><option
								value="0">请选择</option>
							<option value="1" 
						<c:if test="${member.roleid=='1'}">
						selected
						</c:if>>管理员</option>
							<option value="2"
						<c:if test="${member.roleid=='2'}">
						selected
						</c:if>>客户经理</option></select></cite></li>
			</ul>
         </c:if>
		</div>
		<!-- 显示添加成功 -->
		<span class="green">${success}</span>
	</form>
</body>